# coding=utf-8
# 日志组件
import logging
import sys
from logging.handlers import TimedRotatingFileHandler

class FamilyLogger(object):
    """QQ邮箱服务"""
    # 指定logger输出格式
    formatter = logging.Formatter('%(asctime)s %(levelname)-8s: %(message)s')

    # 文件日志
    logFilePath = 'log/familyCloud.log'
    #logFilePath = '/home/ftpadmin/FamilyCloudServer/log/familyCloud.log'
    file_handler = TimedRotatingFileHandler(logFilePath, when="d", interval=1, backupCount=10)
    # file_handler = logging.FileHandler("/logs/familyCloud.log")
    file_handler.setFormatter(formatter)  # 可以通过setFormatter指定输出格式

    # 控制台日志
    console_handler = logging.StreamHandler(sys.stdout)
    console_handler.formatter = formatter  # 也可以直接给formatter赋值

    def __init__(self):
        """ 邮箱服务初始化"""
        pass

    def getLogger(self,app_name='root'):
        """"获取logger实例，如果参数为空则返回root logger"""
        logger = logging.getLogger(app_name)

        # 为logger添加的日志处理器
        logger.addHandler(self.file_handler)
        logger.addHandler(self.console_handler)

        # 指定日志的最低输出级别，默认为WARN级别
        logger.setLevel(logging.DEBUG)
        return logger


